#ifndef __BASESOCKET_H_
#define __BASESOCKET_H_

#define DATA_COUNT

#include "com/DllDef.h"
#ifdef _WIN32
#include <process.h>
#define FD_SETSIZE 1024
#include <winsock2.h>
#include <WS2TCPIP.H>
#include <errno.h>
#include "com/common.h"
#pragma comment(lib,"ws2_32.lib")
typedef int socklen_t;

class CSocketInitializer
{
public:
	CSocketInitializer(void)
	{
		WORD wVersion; 
		WSADATA wsaData;
		wVersion = MAKEWORD(2,2);
		WSAStartup(wVersion,&wsaData);
	}
	virtual ~CSocketInitializer(void)
	{
		WSACleanup(); 
	}
};
#else
#ifndef SOCKET
#define SOCKET int
#endif

#include <sys/time.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <unistd.h>
#include <sys/uio.h>
#include <fcntl.h>
#include <semaphore.h>
#include <pthread.h>
#include <assert.h>
#include <memory.h>
#include <stdio.h>
#include <stdlib.h>
#include <linux/rtc.h>
#include <errno.h>
#include <sys/epoll.h>

#define SOCKET_ERROR   (-1)
#define INVALID_SOCKET (-1)
#define closesocket(s) close(s)
#endif

#define MAX_SOCK_BUFF_LEN 1024*1024

typedef struct tagTcpConn
{
	int	nClientID;
	unsigned long ulLastRecvTime;
	unsigned long ulLastSendTime;
	tagTcpConn()
	{
		nClientID = 0;
		ulLastRecvTime = 0;
		ulLastSendTime = 0;
	}
}TcpConn;

class DLL_EXT_CLASS CBaseSocket
{
public:
	CBaseSocket(void);
	~CBaseSocket(void);

	void Close(void);
	void Close(int nSock);
	bool SetNonBlocking(int nSock);
	bool SetNonBlocking(void);
	void SetRcvSndBuff(void);
	void SetRcvSndBuff(int nSock);

	SOCKET GetSocket()
	{
		return m_hSocket;
	}

protected:
	SOCKET	m_hSocket;
};
#endif
